import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:pizza_test/const/const.dart';
import 'package:pizza_test/model/chefmodel.dart';
import 'package:pizza_test/screen/view/pizza_list.dart';

class ChefHeader extends StatelessWidget {

  final Chef chef;
  final Function beginAction;
  final Function stopAciton;
  final Function finishPizzaion;
  final Function(Chef current, String name, Pizza p) changePizzaToOtherAction;

  ChefHeader({this.chef, this.beginAction, this.stopAciton, this.finishPizzaion, this.changePizzaToOtherAction});

  void start() {
    
  }
  @override
  Widget build(BuildContext context) {
    Size screenSize = MediaQuery.of(context).size;
    return Container(
        color: Colors.grey[200],
        child: Container(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                padding: const EdgeInsets.all(10),
                child: Image.network(chef.avatar,)
              ),

              Center(
                child: CupertinoSwitch(
                  value: chef.iswork,
                  onChanged: (value){
                    if(chef.iswork){
                        stopAciton(chef);
                      } else {
                        beginAction(chef);
                        chef.callback = finishPizzaion;
                      }
                  },
                ),
              ),

              Divider(),
              Container(
                margin: const EdgeInsets.only(left: 10),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Text(chef.name, style: TextStyle(fontWeight: FontWeight.bold),),
                    SizedBox(height: 10),
                    Text("Remaining Pizza: ${chef.pizzas.length}"),
                    SizedBox(height: 10),
                    Text("Speed:${chef.speed} second per pcizza")
                  ],
                ),
              ),
              Container(
                  color: Colors.white,
                  height: screenSize.height * 0.45,
                  child:ListView.builder(
                    itemCount: chef.pizzas.length,
                    itemBuilder: (context,idx) {
                      return PizzaList(chef.pizzas[idx], pizzasColors[chef.name],(String chefName, Pizza p){
                        changePizzaToOtherAction(chef, chefName, p);
                      });
                    },
                  )
                ),
            ],
          ),
        ),
      );
  }
}

